/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.mortbay.jetty.pico.pages;

import java.util.List;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.mortbay.jetty.pico.dao.category.CategoryDAO;
import org.mortbay.jetty.pico.entities.Category;

/**
 *
 * @author Hnmtuan
 */
public class Categories {

    @Property
    private Category ownCate;
    @Property
    private String cateID;
    @Inject
    private CategoryDAO categoryDAO;

    // onActivate() is called by Tapestry to pass in the activation context from the URL.
    void onActivate(String cateId) {
        this.cateID = cateId;
        if (cateID == null || cateID.trim().equalsIgnoreCase("")) {
            List<Category> list = categoryDAO.getParentCategories();
            ownCate = (list == null || list.size() < 1) ? null : list.get(0);
            return;
        }
        ownCate = categoryDAO.getCategoryById(cateID);
    }
}
